<template>
  <div class="operlogAdd" v-loading="detailInfoShow">
    <!-- 筛选按钮 -->
    <div class="search-button" v-if="!contactAddShow">
      <el-button
        v-if="pageType !== 'detail'"
        class="btn save"
        @click="handleAddSave(operlogFormRef)"
        ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
        >保存</el-button
      >
      <el-button class="btn direction" @click="handleBack"
        ><el-icon class="icon" color="#fff"> <Back /> </el-icon
        >返回</el-button
      >
    </div>
    <el-collapse v-model="activeNames">
      <!-- 基础信息 -->
      <el-collapse-item
        name="1"
        v-if="!contactAddShow"
        :class="contactAddShow ? 'customInfoUpClass' : 'customInfoDownClass'"
      >
        <template #title>
          <span class="circle"></span>
          <span class="collapse-title">日志信息</span>
        </template>
        <div class="operlog-info">
          <el-form
            :model="operlogForm"
            ref="operlogFormRef"
            :rules="queryRules"
            label-width="100"
            v-enterToNext
            :disabled="pageType === 'detail'"
          >
            <el-row>
              <el-col :span="12">
                <el-form-item label="操作模块："
                  >{{ operlogForm.title }} /
                  {{ typeFormat(operlogForm) }}</el-form-item
                >
                <el-form-item label="登录信息："
                  >{{ operlogForm.operName }} / {{ operlogForm.operIp }}
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="请求地址：">{{
                  operlogForm.operUrl
                }}</el-form-item>
                <el-form-item label="请求方式：">{{
                  operlogForm.requestMethod
                }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="操作方法：">{{
                  operlogForm.method
                }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="请求参数：">{{
                  operlogForm.operParam
                }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="返回参数：">{{
                  operlogForm.jsonResult
                }}</el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="操作状态：">
                  <div v-if="operlogForm.status === 0">正常</div>
                  <div v-else-if="operlogForm.status === 1">失败</div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="消耗时间："
                  >{{ operlogForm.costTime }}毫秒</el-form-item
                >
              </el-col>
              <el-col :span="10">
                <el-form-item label="操作时间：">{{
                  parseTime(operlogForm.operTime)
                }}</el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item
                  label="异常信息："
                  v-if="operlogForm.status === 1"
                  >{{ operlogForm.errorMsg }}</el-form-item
                >
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script setup>
const { proxy } = getCurrentInstance();
const { sys_oper_type } = proxy.useDict("sys_oper_type", "sys_common_status");
const emit = defineEmits([
  "operlogAddShow",
  "update:operlogAddShow",
  "refreshList",
]);
const props = defineProps({
  pageType: {
    type: String,
    default: "add",
  },
});
const activeNames = ref(["1"]);
const operlogFormRef = ref();
const detailInfoShow = ref(false);

const operlogFormTemplate = {
  operlogId: undefined,
  operlogCode: undefined,
  operlogName: undefined,
  operlogSort: 0,
  status: "0",
  remark: undefined,
};
const data = reactive({
  operlogForm: JSON.parse(JSON.stringify(operlogFormTemplate)),
  queryRules: {},
  contactTypeList: [],
  templateList: [],
  provinceList: [],
  cityList: [],
  areaList: [],
  userList: [],
  operlogList: [],
});
const { operlogForm, queryRules } = toRefs(data);
const contactAddShow = ref(false);

// 返回
const handleBack = () => {
  emit("updateEvaluateAddShow", false);
  emit("update:operlogAddShow", false);
  operlogForm.value = JSON.parse(JSON.stringify(operlogFormTemplate));
};

// 处理详情信息
const handleDetailInfo = async (data) => {
  operlogForm.value = data;
};

/** 操作日志类型字典翻译 */
function typeFormat(row, column) {
  return proxy.selectDictLabel(sys_oper_type.value, row.businessType);
}

defineExpose({
  handleDetailInfo,
});
</script>
<style lang="scss" scoped>
:deep(.el-collapse-item__header) {
  background-color: #f8faff;
}
.operlogAdd {
  padding: 20px 20px;
  width: 100%;
  height: 100%;
  :deep(.el-date-editor.el-input, .el-date-editor.el-input__wrapper) {
    width: 268px !important;
    height: 34px !important;
  }
  .search-button {
    position: absolute;
    top: -45px;
    right: 60px;
    display: flex;
    .btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 90px;
      height: 34px;
      padding: 10px;
      // margin-right: 20px;
      font-size: 14px;
      border-radius: 4px;
      user-select: none;
      cursor: pointer;
    }
    .btn.save {
      color: #fff;
      background: rgba(67, 207, 124, 1);
      border: none;
      &:hover {
        background: rgba(67, 207, 124, 0.85);
      }
    }

    .btn.add {
      .btn.add {
        border: none;
        color: #fff;
        background: rgba(255, 159, 0, 1);
        &:hover {
          background: rgba(255, 159, 0, 0.85);
        }
      }
    }

    .btn.back {
      border: none;
      color: #fff;
      background: rgba(255, 159, 0, 1);
      &:hover {
        background: rgba(255, 159, 0, 0.85);
      }
    }
    .btn.direction {
      border: none;
      color: #fff;
      background: rgba(153, 153, 153, 1);
      &:hover {
        background: rgba(153, 153, 153, 0.85);
      }
    }

    .icon {
      margin-right: 6px;
    }
  }
  .circle {
    margin: 0 10px 0 20px;
    width: 6px;
    height: 6px;
    background: #007cef;
    border-radius: 50%;
  }
  .collapse-title {
    font-weight: bold;
    font-size: 16px;
  }
  .el-collapse,
  .el-collapse-item__wrap {
    border: none;
  }

  .search-input {
    width: 268px;
    height: 34px;
  }
  .operlog-info {
    padding: 20px 10px 5px 10px;
    background-color: #fafafa;
    margin: 10px 0;
  }
  .contact-info {
    padding-top: 20px;
    .table-operate {
      display: flex;
      justify-content: space-around;
      .table-icon {
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }
  }
  .button-position {
    top: 6px;
    right: 30px;
  }
  :deep(.el-input__inner) {
    height: 34px;
  }
  .customInfoUpClass {
    -webkit-animation: customInfoDown 0.8s ease-out;
  }
  .customInfoDownClass {
    -webkit-animation: customInfoDown 0.8s ease-out;
  }

  .contactInfoUpClass {
    -webkit-animation: contactInfoUp 0.8s ease-out;
  }
  .contactInfoDownClass {
    -webkit-animation: contactInfoUp 0.8s ease-out;
  }
  @-webkit-keyframes customInfoUp {
    0% {
      opacity: 0;
      -webkit-transform: translateY(80px);
    }

    100% {
      opacity: 1;
      -webkit-transform: translateY(0px);
    }
  }
  @-webkit-keyframes customInfoDown {
    0% {
      opacity: 0;
      -webkit-transform: translateY(-80px);
    }

    100% {
      opacity: 1;
      -webkit-transform: translateY(0px);
    }
  }
  @-webkit-keyframes contactInfoUp {
    0% {
      opacity: 0;
      -webkit-transform: translateY(80px);
    }

    100% {
      opacity: 1;
      -webkit-transform: translateY(0px);
    }
  }
}
</style>
